%% Create CV data from new set

% Training CV
% helpful + title
titleCVTrain = make_sparse_title(train(bsxfun(@gt, [train().category], 6)));
helpfulCVTrain = make_helpful(train(bsxfun(@gt, [train().category], 6)));

% Join matrix into one large feature matrix
% includes the original set  DO NOT USE
%XcvTrainall = [XcvTrain titleCVTrain helpfulCVTrain];
XcvTrainHelpTitle = [titleCVTrain helpfulCVTrain];

% Test CV
% helpful + title
titleCVTest = make_sparse_title(train(bsxfun(@lt, [train().category], 7)));
helpfulCVTest = make_helpful(train(bsxfun(@lt, [train().category], 7)));

% Join matrix into one large feature matrix
% includes the original set  DO NOT USE
%XcvTestall = [XcvTest titleCVTest helpfulCVTest];
XcvTestHelpTitle = [titleCVTest helpfulCVTest];

%% Internal RMSE Testing

% Run liblinear on the test set
%  [results.intersect, info, yhat] = lin_liblinear(XcvTrainHelpTitle, YcvTrain, ...
%    XcvTestHelpTitle, YcvTest, 7);


% Run lib_linear
%[results.intersect, info, yhat] = lin_liblinear(XhelpTitle, Y, ...
%    XtesthelpTitle, zeros(size(XtesthelpTitle,1),1), 7);

%p = exp(info.vals);
%p = bsxfun(@times, p, 1./sum(p,2));

%ratings = [1 2 4 5];

%Yhat_exp = sum(bsxfun(@times, p, ratings),2);


% %% Run SVM with new set - CV only
% % Inital results (11/29):
% % For solver 7 
% % best C is: 1 
% % RMSE is: 1.17358
% % Expected RMSE is: 1.02936

%% Playing with the data

% % Train CV Set
% idx = find(sum(XcvTrainHelpTitle,1) == 0);
% prunedXcvTrainHelpTitle = XcvTrainHelpTitle;
% prunedXcvTrainHelpTitle(:,idx) = [];
% 
% % Test CV Set
% idx_test = find(sum(XcvTestHelpTitle,1)==0);
% prunedXcvTestHelpTitle = XcvTestHelpTitle;
% prunedXcvTestHelpTitle(:,idx_test) = [];
% 
% %% Try creating a Kernel
% % Does not work!  Still too much memory
% % Use kernel
% k = @(x,x2) kernel_intersection(x, x2);
% [results.intersect, info, Yhat] = kernel_liblinear(prunedXcvTrainHelpTitle, YcvTrain, prunedXcvTestHelpTitle, YcvTest, k);
% 
